﻿<%@ Control Language="C#" AutoEventWireup="true" Inherits="Portal.Data.Webparts.WebpartControl" %>
<%@ Import Namespace="System.Globalization" %>
<%@ Import Namespace="Portal.Core.Helper" %>
<%@ Import Namespace="Portal.Data.Config" %>
<%@ Import Namespace="Portal.Data.Webparts" %>
<%if (Items.Items.Count > 0)
  { %>
<span class="tit_thugian">
    <a target="_blank" href="http://truyengicungco.com/"><%=Config.DisplayTitle %></a>
</span>
<div class="list_dangdoc">
    <ul class="tt-fixed">
        <asp:Repeater ID="Items" runat="server">
            <ItemTemplate>
                <li rel="popover" data-content="<%#Eval("Description")%>" data-original-title="<%#Eval("FullName")%> [<%#Eval("LastChapTitle")%>]">
                    <a href="<%#Eval("WebUrl")%>" class="hot_thumb">
                        <div class="thumb w143 shadow" style="background: url('<%#Eval("Thumb142")%>')"></div>
                    </a>
                    <a href="<%#Eval("WebUrl")%>" class="hot_tit"><%#Eval("FullName")%></a>
                    <div class="hot_view">
                        <span class="sl_view"><%#Portal.Core.Utils.Process.GetTotalDisplay((int)Eval("Visit") )%></span>
                        <span class="hot_date"><%#FriendlyDatetime(Eval("ModifiedDate")) %></span>
                    </div>
                </li>
            </ItemTemplate>
        </asp:Repeater>
    </ul>
</div>
<style>
    .tt-fixed li{ width: 140px !important;}
</style>
<% } %>
<script runat="server">    
    public override WebpartConfig NewConfig
    {
        get { return new TieuThuyetConfig(); }
    }

    public TieuThuyetConfig PartConfig
    {
        get { return (TieuThuyetConfig)Config; }
    }

    private const string UrlFormat = "http://truyengicungco.com/services/jsondata.aspx?acc=admin&pwd=truyengi123@&{0}";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            try
            {
                var jsondata = Portal.Data.Crawler.Common.GetHtmlSources(string.Format(UrlFormat, PartConfig.Queries));
                if (jsondata.Length > 0)
                {
                    var data = JsonHelper.JsonDeserialize<Portal.Data.Entity.TieuThuyetJson.JsonBookPaging>(jsondata);
                    if (data != null && data.Books.Count > 0)
                    {
                        Items.DataSource = data.Books.Take(PartConfig.Max);
                        Items.DataBind();
                    }
                }
            }
            catch (Exception ex) { }
        }
    }
    public string FriendlyDatetime(object sd)
    {
        var d = DateTime.ParseExact(sd.ToString(), "yyyyMMddHHmmss", CultureInfo.InvariantCulture);
        return Portal.Core.Common.FriendlyDateDisplay(d);
    }
</script>
